/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tk.eigh.ksvg.renderer;

import java.io.IOException;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;

/**
 *
 * @author nt
 */
public abstract class SVGRenderer extends Renderer {

    protected final static Logger LOGGER = Logger.getLogger(SVGRenderer.class.getName());
    protected static int indent = 0;

    @Override
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
        super.encodeBegin(context, component);
        if (!component.isRendered()) {
            return;
        }
        if (indent > 0) {
            HtmlRendererUtils.writePrettyLineSeparator(context);
        }
        for (int i = 0; i < indent; i++) {
            HtmlRendererUtils.writePrettyIndent(context);
        }
        indent++;
    }

    @Override
    public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
        super.encodeEnd(context, component);
        if (!component.isRendered()) {
            return;
        }
        indent--;
        if (!component.getChildren().isEmpty()) {
            HtmlRendererUtils.writePrettyLineSeparator(context);
            for (int i = 0; i < indent; i++) {
                HtmlRendererUtils.writePrettyIndent(context);
            }
        }
    }

    public void renderCommonAttributes(ResponseWriter writer, UIComponent component, FacesContext context) throws IOException {
        //HtmlRendererUtils.renderHTMLAttributes(writer, component, SVG.CONDITIONAL_PROCESSING_ATTRS);
        SVGRendererUtils.renderCoreAttributes(writer, component, context);
    }
}
